package com.spsoft.vatoutinv.config;

import cn.hutool.core.io.resource.ResourceUtil;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.io.IOException;

/**
 * @author wangy
 * @date 2024/2/27 16:14
 */
@Component
public class FontRegisterRunner implements CommandLineRunner {
    @Override
    public void run(String... args) throws IOException, FontFormatException {

        // 读取外部字体资源，然后创建字体
        Font font = Font.createFont(Font.TRUETYPE_FONT, ResourceUtil.getStream("font/simkai.ttf"));
        Font font1 = Font.createFont(Font.TRUETYPE_FONT, ResourceUtil.getStream("font/simsun.ttc"));

        // 注册字体
        GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
        genv.registerFont(font);
        genv.registerFont(font1);

        // 当在其它代码里需要使用字体时，直接使用：
        // Font font = new Font("Source Han Serif SC", fontStyle, size);

    }
}
